<?php

namespace app\models;

use Yii;
use yii\db\ActiveRecord;

class topic extends ActiveRecord{
    public static function tableName(){
	    return "{{%topic%}}";
	 }
	 
   /**	public function rules(){
	   return[
	        ['content','required','message' => '问题不能为空~'],
			['answer','required','message' => '文章html不能为空~'],
		];
	}    */
	
         
	//作废！
	public function upscore($data){
	   if($data){
		   
	   $topicId = $data['topicId'];
	   //在原有的积分上加1;或者从前端那获得已加好的积分(选择后者）
	   $score = $data['score'];
	   $result=$this->updateAll(['score' => $score],['topicId' => $topicId]);
	   if($result>0){
		   $error = 0;
		   return $error;
	   }else{
		   $error = $this->getErrors();
		   return $error;
	     }
	   }else{
		   $error = 2;
		   return $error;
	   }
	}
}
